package samples;

/**
 * User: sudarshan
 * Date: Mar 7, 2008
 * Time: 11:12:39 PM
 */

import JSetL.*;

public class JSetLSample {

    /*
    *                  N-QUEENS PROBLEM
    *
    * Place N queens on a NxN chessboard such that no two queens
    * attack each other, i.e., no two queens can be placed on the
    * same row, the same column or the same diagonal.
    *
    */


    public static final int N = 8;
    public static Set board = new Set(0, N - 1);   // board = {0,..,N-1}
    public static Lst pos = Lst.mkLst(N);       // Lst di N Lvar non iniz.


    public static void main(String[] args) throws Failure {
        SolverClass Solver = new SolverClass();
        for (int i = 0; i < N; i++) {
            Solver.add(((Lvar) pos.get(i)).in(board));
        }
        Solver.allDifferent(pos);

        for (int i = 0; i < N - 1; i++) {
            for (int j = i + 1; j < N; j++) {
                Solver.add(((Lvar) pos.get(j)).sum(j).sub((Lvar) pos.get(i)).neq(i));
                Solver.add(((Lvar) pos.get(i)).sum(j).sub((Lvar) pos.get(j)).neq(i));
            }
        }

        Solver.solve();

        for (int i = 0; i < N; i++) {
            System.out.print("\nQueen" + (i + 1) + " (" + i + ",");
            ((Lvar) pos.get(i)).print();
            System.out.print(")");
        }
        return;
    }
}

